import Vue from 'vue'
import App from './App'
import store from './store'
import api from './config/api'
import base from './common/app'
import dayjs from 'dayjs'
Vue.config.productionTip = false

Vue.prototype.$store = store
Vue.prototype.$api = api
Vue.prototype.$app = base
Vue.prototype.dayjs = dayjs
/*无状态提示信息*/
Vue.prototype.$alert = function(msg = '', icon = 'none', url = '', openType = 'navigate') {
	base.alert(msg, icon, url, openType);
};

/*弹出加载框*/
Vue.prototype.$loading = function(msg = '', mask = true) {
	base.loading(msg, mask);
};

/*是否登录*/
Vue.prototype.$initLogin = function() {
	if (!uni.getStorageSync('isLogin')) {
		base.login();
	}
};

/*初始化页面标题*/
Vue.prototype.$initPageTitle = function(pageTitle = '早知道') {
	// #ifdef H5
	document.title = pageTitle;
	// #endif
};

if (process.env.NODE_ENV !== 'production') {
	// console.log = () => {}//开发环境去除看一下效果
}else{
	//正式环境去除
	console.log = () => {}
}
Vue.filter('unitConverter', (value)=>{
  if (!value) return 0
  // 获取整数部分
  const intPart = Math.trunc(value)
  // 整数部分处理，增加,
  const intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
  // 预定义小数部分
  let floatPart = ''
  // 将数值截取为小数部分和整数部分
  const valueArray = value.toString().split('.')
  if (valueArray.length === 2) { // 有小数部分
    floatPart = valueArray[1].toString() // 取得小数部分
    return intPartFormat + '.' + floatPart
  }
  return intPartFormat + floatPart
})
App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()
